﻿//-----------------------------------------------------------------------
// <copyright file="TreasureMapPage.cs" company="Microsoft Corporation">
//     Copyright Microsoft Corporation. All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.) This is sample code only, do not use in production environments.
// </copyright>
//-----------------------------------------------------------------------
namespace Microsoft.ALMRangers.VsarTreasureMap.WindowsStoreApp.ViewModels
{
    using System;
    using Microsoft.ALMRangers.VsarTreasureMap.WindowsStoreApp.MVVMSupport;
    using Windows.ApplicationModel.DataTransfer;

    /// <summary>
    /// View Model Representation of the Treasure Map Page.
    /// </summary>
    public class TreasureMapPage : IShare
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TreasureMapPage"/> class.
        /// </summary>
        public TreasureMapPage()
        {
            this.GoToCommand = new Command<string>(this.GoToCategory);
            this.GoBack = new Command(() =>
                {
                    Navigation.GoBack();
                });

            DataTransferManager.GetForCurrentView().DataRequested += this.TreasureMapPage_DataRequested;
        }

        /// <summary>
        /// Gets or sets the command to navigate to a particular piece of guidance.
        /// </summary>
        public Command<string> GoToCommand { get; set; }

        /// <summary>
        /// Gets the command to go back.
        /// </summary>
        public Command GoBack { get; private set; }

        /// <summary>
        /// event handler to navigate to the selected Category page.
        /// </summary>
        /// <param name="category">string representation of the Category to navigate to.</param>
        public void GoToCategory(string category)
        {
            Navigation.Navigate(typeof(Microsoft.ALMRangers.VsarTreasureMap.WindowsStoreApp.Views.Category), Convert.ToInt32(category));
        }

        /// <summary>
        /// Deregisters the share handler.
        /// </summary>
        public void Deregister()
        {
            DataTransferManager.GetForCurrentView().DataRequested -= this.TreasureMapPage_DataRequested;
        }

        /// <summary>
        /// Event handler for the share event.
        /// </summary>
        /// <param name="sender">The parameter is not used.</param>
        /// <param name="args">The parameter is not used.</param>
        public void TreasureMapPage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            args.Request.FailWithDisplayText("Nothing can be shared on this page, but other pages do have treasure that can be shared! Happy exploring!");
        }
    }   
}
